<template>
    <div class="table-container">
        <table-container
            ref="table685"
            :form-id="formId"
            :filter-data="filterData"
            :common-placeholder="commonPlaceholder"
            :show-row-column="showRowColumn"
            :list="list"
            :list-loading="listLoading"
            :field-valid="fieldValid"
            :button-list="buttonList"
            :has-common-filter = "hasCommonFilter"
            :fixed-columns = "fixedColumns"
            :height-percentage = "heightPercentage"
            :has-tab= "hasTab"
            :master-table="masterTable"
            @loadMore="loadMore"
            @onSortClick="onSortClick"
            @onRowButtonClick="onRowButtonClick">
            <el-pagination
                :current-page="pager.offset"
                :page-sizes="[20, 30, 50, 100]"
                :page-size="pager.limit"
                :total="totalData"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"/>
        </table-container>
        <el-dialog title="选择导入的Excel" v-if="dialogImportVisible" :visible.sync="dialogImportVisible">
            <import-data :import-excel-data="importExcelData"/>
        </el-dialog>
        <el-dialog title="导出字段" v-if="dialogExportVisible" :visible.sync="dialogExportVisible">
            <export-data :export-excel-data="exportExcelData"/>
        </el-dialog>
        <!-- dialogExcVisible -->
        <el-dialog title="选择公式" v-if="dialogExcVisible" :visible.sync="dialogExcVisible">
            <exc-solution :exc-solution-data="excSolutionData"/>
        </el-dialog>

        <el-dialog title="转置表单" v-if="dialogTransVisible" :visible.sync="dialogTransVisible">
            <trans-table :list="transList" :field-valid="fieldValid" :show-row-column="showRowColumn"/>
        </el-dialog>
    </div>
</template>

<script>
import tableContainer from '@/components/table/table-container'
import pagination from '@/mixins/pagination'
import tableInterface from '@/mixins/tableInterface'
import importData from '@/components/BtnPage/importData'
import exportData from '@/components/BtnPage/exportData'
import excSolution from '@/components/BtnPage/excSolution'
import transTable from '@/components/BtnPage/trans'

export default {
    name: 'treetable',
    components: { tableContainer, importData, exportData, excSolution, transTable },
    mixins: [pagination, tableInterface],
    props: {
        heightPercentage: {
            type: Number,
            default: 1
        },
        hasTab: {
            type: Boolean,
            default: false
        },
        masterTable: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            formId: '685',
            // 冻结列数量
            fixedColumns: 3,
            // 没有侧边为false
            isOpen: true,
            // 所有字典的值
            dictValues: {},
            // 模糊搜索
            hasCommonFilter: true,
            commonFilter: '',
            commonPlaceholder: '人数,部门名称,部门编码',
            commonFilterArr: ['DEPVPEOPLECOUNT_NUM', 'ORGDEPARTMENT_CNAME', 'ORGDEPARTMENT_DEPCODE'],
            // 搜索字段
            filterData: {
                DEPVPEOPLECOUNT_NUM: '',
                ORGDEPARTMENT_CNAME: '',
                ORGDEPARTMENT_DEPCODE: '',
                ORGDEPARTMENT_DEPGRADE: '',
                _INTERVAIL_MAX_ORGDEPARTMENT_CREATEDATE: '',
                _INTERVAIL_MIN_ORGDEPARTMENT_CREATEDATE: ''
            },
            showRowColumn: [
                { formColumnId: '21116', relcolumnId: 'ORGDEPARTMENT_DEPCODE', columnId: 'ORGDEPARTMENT_DEPCODE', columnName: '组织编码' },
                { formColumnId: '21117', relcolumnId: 'ORGDEPARTMENT_CNAME', columnId: 'ORGDEPARTMENT_CNAME', columnName: '组织名称' },
                { formColumnId: '92068', relcolumnId: 'DEPVPEOPLECOUNT_NUM', columnId: 'DEPVPEOPLECOUNT_NUM', columnName: '人数' },
                { formColumnId: '21118', relcolumnId: 'ORGDEPARTMENT_ENAME', columnId: 'ORGDEPARTMENT_ENAME', columnName: '组织简称' },
                { formColumnId: '21122', relcolumnId: 'ORGDEPARTMENT_DEPTYPE', columnId: 'ORGDEPARTMENT_DEPTYPE_DICTNAME', columnName: '组织类型' },
                { formColumnId: '21121', relcolumnId: 'ORGDEPARTMENT_DEPGRADE', columnId: 'ORGDEPARTMENT_DEPGRADE_DICTNAME', columnName: '组织级别' },
                { formColumnId: '61637', relcolumnId: 'ORGDEPARTMENT_DEPAREA', columnId: 'ORGDEPARTMENT_DEPAREA_DICTNAME', columnName: '机构区域' },
                { formColumnId: '61638', relcolumnId: 'ORGDEPARTMENT_ISALLOW', columnId: 'ORGDEPARTMENT_ISALLOW_DICTNAME', columnName: '是否享受海岛津贴' },
                { formColumnId: '61639', relcolumnId: 'ORGDEPARTMENT_HANGLEADER', columnId: 'ORGDEPARTMENT_HANGLEADER_DICTNAME', columnName: '挂片领导' },
                { formColumnId: '61640', relcolumnId: 'ORGDEPARTMENT_ISPROTECT', columnId: 'ORGDEPARTMENT_ISPROTECT_DICTNAME', columnName: '是否保护期' },
                { formColumnId: '21124', relcolumnId: 'ORGDEPARTMENT_DEPKIND', columnId: 'ORGDEPARTMENT_DEPKIND_DICTNAME', columnName: '业务条线' },
                { formColumnId: '21123', relcolumnId: 'ORGDEPARTMENT_DEPCOST', columnId: 'ORGDEPARTMENT_DEPCOST_DICTNAME', columnName: '成本中心' },
                { formColumnId: '21119', relcolumnId: 'ORGDEPARTMENT_COMPID', columnId: 'ORGDEPARTMENT_COMPID_DICTNAME', columnName: '所属公司' },
                { formColumnId: '21120', relcolumnId: 'ORGDEPARTMENT_PARENTID', columnId: 'ORGDEPARTMENT_PARENTID_DICTNAME', columnName: '上级组织' },
                { formColumnId: '21134', relcolumnId: 'ORGDEPARTMENT_CREATEDATE', columnId: 'ORGDEPARTMENT_CREATEDATE_NEWDATE', columnName: '成立日期' },
                { formColumnId: '21132', relcolumnId: 'ORGDEPARTMENT_LEADER', columnId: 'ORGDEPARTMENT_LEADER_DICTNAME', columnName: '分管领导' },
                { formColumnId: '50755', relcolumnId: 'ORGDEPARTMENT_LEADERSHIP', columnId: 'ORGDEPARTMENT_LEADERSHIP_DICTNAME', columnName: '协管领导' },
                { formColumnId: '21130', relcolumnId: 'ORGDEPARTMENT_XORDER', columnId: 'ORGDEPARTMENT_XORDER', columnName: '排序' },
                { formColumnId: '21138', relcolumnId: 'ORGDEPARTMENT_REMARK', columnId: 'ORGDEPARTMENT_REMARK', columnName: '备注' },
                { formColumnId: '92069', relcolumnId: 'ORGDEPARTMENT_DISABLEDDATE', columnId: 'ORGDEPARTMENT_DISABLEDDATE', columnName: '失效日期' },
                { formColumnId: '83907', relcolumnId: 'ORGDEPARTMENT_UPDATETIME', columnId: 'ORGDEPARTMENT_UPDATETIME_NEWDATE', columnName: '最近修改日期' },
                { formColumnId: '61762', relcolumnId: 'ORGDEPARTMENT_ISFININSTITU', columnId: 'ORGDEPARTMENT_ISFININSTITU_DICTNAME', columnName: '是否人行金融机构' },
                { formColumnId: '61763', relcolumnId: 'ORGDEPARTMENT_FININSTITU', columnId: 'ORGDEPARTMENT_FININSTITU', columnName: '人行金融机构代码' },
                { formColumnId: '61764', relcolumnId: 'ORGDEPARTMENT_WEBNUM', columnId: 'ORGDEPARTMENT_WEBNUM', columnName: '网点号' },
                { formColumnId: '61765', relcolumnId: 'ORGDEPARTMENT_PROAGENCCODE', columnId: 'ORGDEPARTMENT_PROAGENCCODE', columnName: '省联社机构代码' },
                { formColumnId: '84140', relcolumnId: 'ORGDEPARTMENT_MANAGEREGION', columnId: 'ORGDEPARTMENT_MANAGEREGION_DICTNAME', columnName: '管辖区域' }
            ],
            list: [],
            listLoading: true,
            // 字段权限
            fieldValid: {},
            buttonValid: {},
            buttonList: [
                { buttonName: '编辑', icon: 'el-icon-plus', buttonId: 2414, colorType: 'primary' },
                { buttonName: '新增', icon: 'el-icon-search', buttonId: 2414, colorType: 'primary' },
                { buttonName: '删除', icon: 'el-icon-delete', buttonId: 2414, colorType: 'primary' },
                { buttonName: '查看', icon: 'el-icon-plus', buttonId: 2414, colorType: 'primary' },
                { buttonName: '下载', icon: 'el-icon-download', buttonId: 2414, colorType: 'primary' },
                { buttonName: '下载2', icon: 'el-icon-download', buttonId: 2414, colorType: 'primary' },
                { buttonName: '下载3', icon: 'el-icon-download', buttonId: 2414, colorType: 'primary' },
                { buttonName: '下载4', icon: 'el-icon-download', buttonId: 2414, colorType: 'primary' }
            ],
            requestParam: {
                'ORGVORGANIZATION_DEPCODE': ''
            },
            sortParams: {},
            dialogImportVisible: false,
            importExcelData: {
                formId: 2057,
                templateFileid: 1022,
                templateFilename: '新员工入职登记导入模板(红色字段为必填字段).xls',
                buttonId: 2954
            },
            dialogExportVisible: false,
            exportExcelData: {
                formId: 2057,
                formFieldsize: 0,
                filename: '新员工入职列表',
                buttonId: 6805,
                filterData: this.filterData,
                requestParam: this.requestParam
            },
            dialogExcVisible: false,
            excSolutionData: {
                formId: 4924,
                formButtonId: 8585
            },
            dialogTransVisible: false,
            transList: []
        }
    },
    async created() {
        this.$eventBus.$on('common-filter', (...args) => {
            // todo something
            console.log(args[0])
            this.commonFilter = args[0]
            this.commonFilterArr.forEach(item => {
                this.filterData[item] = this.commonFilter
            })
        }, this)
        this.$eventBus.$on('zhubiaochuandi', (...args) => {
            const row = args[0]
            // 只有非主表且有参数时才能去接收主表转过来的参数
            if (!this.masterTable && row) {
                this.requestParam = {
                    'ORGVORGANIZATION_ORGCODE': row.ORGVORGANIZATION_ORGCODE
                }
                this._cardformInitData()
            }
        }, this)
    },
    methods: {
        searchForm() {
            this._cardformInitData()
        },
        loadMore() {
            this._cardformInitData('loadMore')
        },
        onRowButtonClick(e) {
            // list为一个数组
            console.log(e)
            this.transList = e.list
            this.dialogTransVisible = true
            // 删除实例
            // this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            //     confirmButtonText: '确定',
            //     cancelButtonText: '取消',
            //     type: 'warning'
            // }).then(() => {
            //     // 点击确定
            //     // 可以做提交请求的操作
            //     // 下面是提示
            //     this.$message({
            //         type: 'success',
            //         message: '删除成功!'
            //     })
            // }).catch(() => {
            //     this.$message({
            //         type: 'info',
            //         message: '已取消删除'
            //     })
            // })
        },
        onSortClick(e) {
            this.sortParams = {}
            this.sortParams[e.prop] = e.order === 'ascending' ? 'asc' : 'desc'
            this._cardformInitData()
        }
    }
}
</script>

